package net.xuele.learn.queue;




import java.util.LinkedHashMap;
import java.util.Map;

public class SimpleCache implements Cache<Integer, Object> {
    private Integer size;

    private final LinkedHashMap<Integer, Object> delegate;

    public SimpleCache(int size) {
        delegate = new LinkedHashMap<Integer, Object>(16, 0.75F, true) {

            private static final long serialVersionUID = -2370451831905407189L;

            protected boolean removeEldestEntry(Map.Entry<Integer, Object> eldest) {
                return this.size() > size;
            }
        };
    }

    @Override
    public boolean put(Integer s, Object o) {
        delegate.put(s, o);
        return true;
    }

    @Override
    public Object get(Integer s) {
        return delegate.get(s);
    }

    @Override
    public Object del(Integer s) {
        return delegate.remove(s);
    }

}
